/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.xuexiang.xuidemo.view;

import ohos.agp.components.AttrSet;
import ohos.agp.components.Component;
import ohos.agp.components.DirectionalLayout;
import ohos.agp.components.LayoutScatter;
import ohos.agp.components.ListContainer;
import ohos.app.Context;

import com.xuexiang.xui_lib.util.UntilTNT;
import com.xuexiang.xui_lib.util.ViewModel;
import com.xuexiang.xuidemo.ResourceTable;
import com.xuexiang.xuidemo.provider.SetterProvider;

import java.util.ArrayList;
import java.util.List;

/**
 * listtainer控件只放置一个text
 *
 * @since 2021-03-30
 */
class Listtainer_onetext extends DirectionalLayout {
    private Context context;
    private Component ct;
    private ListContainer listContainer;
    private List<UntilTNT> list;
    private com.xuexiang.xuidemo.provider.SetterProvider SetterProvider;
    private ViewModel viewModel;
    String[] data = null;

    public Listtainer_onetext(Context context) {
        super(context);
        this.context = context;
        viewModel = new ViewModel(context);
        initview();
        //  data=viewModel.getStringResource(ResourceTable.Strarray_serch_array);
    }

    public Listtainer_onetext(Context context, AttrSet attrSet) {
        super(context, attrSet);
        this.context = context;
        viewModel = new ViewModel(context);
        initview();
    }

    public Listtainer_onetext(Context context, AttrSet attrSet, String styleName) {
        super(context, attrSet, styleName);
        this.context = context;
        viewModel = new ViewModel(context);
        initview();
    }

    private void initview() {
        ct = LayoutScatter.getInstance(context).parse(ResourceTable.Layout_listtainer_onetext_layout, this, true);
        listContainer = (ListContainer) ct.findComponentById(ResourceTable.Id_listconid);
        SetList();
    }

    public void SetList() {
        data = viewModel.getStringResource(ResourceTable.Strarray_drop_array);//获取json文件,Strarray_drop_content
        list = new ArrayList<>();
        for (int i = 0; i < data.length; i++) {
            UntilTNT untilTNT = new UntilTNT();
            untilTNT.setDisplay(false);
            untilTNT.setName(data[i]);
            list.add(untilTNT);
        }
        SetterProvider = new SetterProvider(list, context);
        listContainer.setItemProvider(SetterProvider);
    }
}
